package edu.gyc.test;

import java.util.concurrent.Semaphore;

enum GirlEnum{
    ONE(1,"朱洁静"),TWO(2,"赵雨静"),THREE(3,"柳如是"),
    FOUR(4,"周慧敏"),FIVE(5,"徐睿"),SIX(6,"邱淑贞");
    private int id;
    private String name;

    GirlEnum(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static GirlEnum get(int index) {
        GirlEnum[] girlEnums=GirlEnum.values();
        for (GirlEnum girlEnum : girlEnums) {
            if (girlEnum.getId() == index) {
                return girlEnum;
            }
        }
        return  null;
    }
}
public class GirlSemaphore {
    public static void main(String[] args) {
        Semaphore semaphore=new Semaphore(6);
        for (int i = 0; i < 19; i++) {
            int finalI = i;
            new Thread(()->{
          try{
              semaphore.acquire();
              int n= finalI %6+1;
              System.out.println("美女\t"+GirlEnum.get(n).getName()+": 很高兴为您服务，"+Thread.currentThread().getName());
              Thread.sleep(3000);
              System.out.println(Thread.currentThread().getName()+"\t:短暂的60分钟，好爽呀！");
          }catch (Exception e){
              e.printStackTrace();
          }finally {
              semaphore.release();
          }
            },"客人"+i).start();
        }
    }
}
